package com.bac.rentmap.web.controller.datastore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.bac.rentmap.datastore.DatastoreEntityProvider;
import com.bac.rentmap.datastore.EntityRestriction;

public class DatastoreViewController extends AbstractCommandController{
    private DatastoreEntityProvider datastoreEntityProvider;
    @Override
    protected ModelAndView handle(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {
        EntityRestriction entityRestriction = (EntityRestriction) command;
        Map model = new HashMap();
        List<?> entities = datastoreEntityProvider.find(entityRestriction);
        model.put("entities", entities);
        return new ModelAndView("admin/datastore/index", model);
    }
    @Required
    public void setDatastoreEntityProvider(
            DatastoreEntityProvider datastoreEntityProvider) {
        this.datastoreEntityProvider = datastoreEntityProvider;
    }
}
